<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>图书交易平台 - 登录</title>
<%--    <link href="${pageContext.request.contextPath}\style\style.css" rel="stylesheet">--%>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}\style\style.css">
</head>
<body>
    <div class="container">
        <div class="left-side">
            <!-- 背景图片会通过 CSS 设置 -->
        </div>
        <div class="right-side">
            <div class="login-box">
                <h2>欢迎登录</h2>
                <form class="login-form" action="login" method="post" onsubmit="return validateForm()">
                    <div class="input-group">
                        <input type="text" name="username" required>
                        <label>用户名</label>
                    </div>
                    <div class="input-group">
                        <input type="email" name="email" required>
                        <label>邮箱</label>
                    </div>

                    <div class="form-group">
                        <label for="remember">自动登录时间</label>
                        <select id="remember" name="remember">
                            <option value="">不自动登录</option>
                            <option value="1">1天</option>
                            <option value="7">7天</option>
                            <option value="30">30天</option>
                        </select>
                    </div>


<%--                    <div class="remember-forgot">--%>
<%--                        <label>--%>
<%--                            <input type="checkbox" name="remember"> 记住我--%>
<%--                        </label>--%>
<%--                    </div>--%>
                    <% 
                        String error = (String) request.getAttribute("error");
                        if(error != null) {
                    %>
                        <div class="error-message" style="color: red; margin-bottom: 10px;">
                            <%= error %>
                        </div>
                    <% } %>
                    <button type="submit">登录</button>
                    <div class="register-link">
                        还没有账号？<a href="register.jsp">立即注册</a>
                    </div>
                </form>
                <%
                    error = (String)request.getAttribute("error");
                    if(error != null) {
                %>
                <div class="error-message"><%=error%></div>
                <%
                    }
                %>
            </div>
        </div>
    </div>

    <script>
    function validateForm() {
        var username = document.forms["login-form"]["username"].value;
        var email = document.forms["login-form"]["email"].value;
        
        // 验证用户名
        if (username.trim() === "") {
            alert("请输入用户名！");
            return false;
        }
        
        if (username.length < 2 || username.length > 20) {
            alert("用户名长度必须在2-20个字符之间！");
            return false;
        }
        
        // 验证邮箱
        if (email.trim() === "") {
            alert("请输入邮箱！");
            return false;
        }
        
        // 邮箱格式验证
        var emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
        if (!emailPattern.test(email)) {
            alert("请输入有效的邮箱地址！");
            return false;
        }
        
        return true;
    }
    </script>
</body>
</html> 